home *** CD-ROM | disk | FTP | other *** search
/ Delphi Developer's Kit 1996 / Delphi Developer's Kit 1996.iso / power / sprites / untdemo3.pas < prev    next >
Pascal/Delphi Source File  |  1995-12-22  |  7KB  |  209 lines

  1. unit Untdemo3;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Mchsprt, ExtCtrls, MChSpBg, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     MChSpriteBgr1: TMChSpriteBgr;
  12.     MChSprite1: TMChSprite;
  13.     MChSprite2: TMChSprite;
  14.     MChSprite3: TMChSprite;
  15.     MChSprite4: TMChSprite;
  16.     MChSprite5: TMChSprite;
  17.     MChSprite6: TMChSprite;
  18.     Button1: TButton;
  19.     Button2: TButton;
  20.     Button3: TButton;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure Button1Click(Sender: TObject);
  25.     procedure Button2Click(Sender: TObject);
  26.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  27.       Shift: TShiftState; X, Y: Integer);
  28.     procedure Button3Click(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  36. function Sprite4PosFunc(AtTime: TDateTime):TPoint;
  37. function Sprite6PosFunc(AtTime: TDateTime):TPoint;
  38. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  39. procedure NoCollide(AtTime: TDateTime);
  40. procedure OnExplosion(SprCollided: TMChSprite; AtTime: TDateTime);
  41.  
  42. var
  43.   Form1: TForm1;
  44.  
  45. implementation
  46.  
  47. {$R *.DFM}
  48.  
  49. var
  50.   CollideFlip, Exploding: Boolean;
  51.  
  52. function Sprite3PosFunc(AtTime: TDateTime):TPoint;
  53.   var
  54.     x,y,alpha: double;
  55.   begin
  56.   alpha:=-2*Pi*(AtTime-Form1.MChSprite3.SprTimeStarted)*24.0*60.0+(90.0-180.0)/180.0*Pi;
  57.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  58.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  59.   y := Form1.MChSpriteBgr1.ClientHeight*0.5 +
  60.     - (Form1.MChSpriteBgr1.ClientWidth *0.55)*sin(alpha);
  61.   Sprite3PosFunc:=Point(round(x),round(y));
  62.   if x>Form1.MChSpriteBgr1.ClientWidth div 2
  63.     then Form1.MChSprite3.SprSetScaleX( (1-1.0*sin(alpha)))
  64.     else Form1.MChSprite3.SprSetScaleX(-(1-1.0*sin(alpha)));
  65.   if y<Form1.MChSpriteBgr1.ClientHeight div 2
  66.     then Form1.MChSprite3.SprSetScaleY( (1-1.0*sin(alpha)))
  67.     else Form1.MChSprite3.SprSetScaleY(-(1-1.0*sin(alpha)));
  68.   end;
  69.  
  70. function Sprite4PosFunc(AtTime: TDateTime):TPoint;
  71.   var
  72.     x,y,alpha: double;
  73.   begin
  74.   alpha:= 2*Pi*(AtTime-Form1.MChSprite4.SprTimeStarted)*24.0*60.0+(90.0+0.0)/180.0*Pi;
  75.   x := Form1.MChSpriteBgr1.ClientWidth /2.0 +
  76.       (Form1.MChSpriteBgr1.ClientWidth /3.0)*cos(alpha);
  77.   y := Form1.MChSpriteBgr1.ClientHeight /2.0 +
  78.     - (Form1.MChSpriteBgr1.ClientWidth /3.0)*sin(alpha);
  79.   Sprite4PosFunc:=Point(round(x),round(y));
  80.   Form1.MChSprite4.SprSetScale(1-0.9*sin(alpha));
  81.   end;
  82.  
  83. function Sprite6PosFunc(AtTime: TDateTime):TPoint;
  84.   begin
  85.   Sprite6PosFunc:=Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  86.                         Form1.MChSpriteBgr1.ClientHeight div 2);
  87.   Form1.MChSprite6.SprSetScale(1.25*(AtTime-Form1.MChSprite6.SprTimeStarted)
  88.          *24.0*60.0*60.0*5.0);
  89.   if (AtTime-Form1.MChSprite6.SprTimeStarted)*24.0*60.0*60.0>17 then
  90.     Form1.MChSprite6.SprHide;
  91.   end;
  92.  
  93. procedure TForm1.FormCreate(Sender: TObject);
  94.   begin
  95.   Exploding:=False;
  96.   MChSprite2.SprShowAt(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  97.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  98.   MChSprite3.SprPosFunc:=Sprite3PosFunc;
  99.   MChSprite4.SprPosFunc:=Sprite4PosFunc;
  100.   MChSprite6.SprPosFunc:=Sprite6PosFunc;
  101.   MChSprite6.SprHideAfter:=True;
  102.   MChSprite6.SprOnCollide:=OnExplosion;
  103.   MChSprite4.SprOnCollide:=OnCollide;
  104.   MChSprite4.SprNoCollide:=NoCollide;
  105.   MChSprite3.SprCruise(-1);
  106.   MChSprite4.SprCruise(-1);
  107.   MChSprite6.SprMoveTo(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  108.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  109.   end;
  110.  
  111. procedure OnCollide(SprCollided: TMChSprite; AtTime: TDateTime);
  112.   begin
  113.   if SprCollided=Form1.MChSprite3 then
  114.     begin
  115.     if not CollideFlip then
  116.       begin
  117.       MessageBeep(MB_ICONASTERISK);
  118.       CollideFlip:=True;
  119.       end;
  120.     if Form1.MChSprite4.SprNextPos.x<Form1.MChSpriteBgr1.ClientWidth div 2 then
  121.       begin
  122.       if Form1.MChSprite4.SprIndex<Form1.MChSprite3.SprIndex then
  123.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite4.SprIndex,
  124.           Form1.MChSprite3.SprIndex);
  125.       end
  126.     else
  127.       begin
  128.       if Form1.MChSprite4.SprIndex>Form1.MChSprite3.SprIndex then
  129.         Form1.MChSpriteBgr1.BgrSprIndexExchangeZ(Form1.MChSprite4.SprIndex,
  130.           Form1.MChSprite3.SprIndex);
  131.       end;
  132.     end;
  133.   end;
  134.  
  135. procedure OnExplosion(SprCollided: TMChSprite; AtTime: TDateTime);
  136.   begin
  137.   if Exploding then
  138.     begin
  139.     SprCollided.SprStop;
  140.     SprCollided.SprHide;
  141.     end;
  142.   if (not Exploding) and (SprCollided=Form1.MChSprite1) then
  143.     begin
  144.     Exploding:=True;
  145.     Form1.MChSprite2.SprColliding:=True;
  146.     Form1.MChSprite5.SprColliding:=True;
  147.     Form1.MChSprite6.SprCruise(20);
  148.     end;
  149.   end;
  150.  
  151. procedure NoCollide(AtTime: TDateTime);
  152.   begin
  153.   if CollideFlip then
  154.     begin
  155.     MessageBeep(MB_OK);
  156.     end;
  157.   CollideFlip:=False;
  158.   end;
  159.  
  160. procedure TForm1.Button1Click(Sender: TObject);
  161.   begin
  162.   Exploding:=False;
  163.   MChSprite6.SprSetScale(0.2);
  164.   MChSprite6.SprMoveTo(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  165.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  166.   Form1.MChSprite1.SprColliding:=True;
  167.   Form1.MChSprite6.SprColliding:=True;
  168.   Form1.MChSprite1.SprGo( Point(Form1.MChSpriteBgr1.ClientWidth,0),
  169.              Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  170.                    Form1.MChSpriteBgr1.ClientHeight div 2), 5 );
  171.   end;
  172.  
  173. procedure TForm1.Button2Click(Sender: TObject);
  174.   begin
  175.   MChSprite5.SprColliding:=False;
  176.   MChSprite5.SprHideAfter:=True;
  177.   MChSprite5.SprGo(Point(Form1.MChSpriteBgr1.ClientWidth,
  178.                          Form1.MChSpriteBgr1.ClientHeight),
  179.                    Point(0,0), 20);
  180.   end;
  181.  
  182. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  183.   Shift: TShiftState; X, Y: Integer);
  184.   begin
  185.   MChSpriteBgr1.MChSpriteBgrMouseDown(Sender,Button,Shift,X,Y);
  186.   if MChSpriteBgr1.BgrSprHitted=MChSprite5 then
  187.     begin
  188.     MChSprite5.SprHideAfter:=False;
  189.     MChSprite5.SprStop;
  190.     end;
  191.   end;
  192.  
  193. procedure TForm1.Button3Click(Sender: TObject);
  194.   begin
  195.   Exploding:=False;
  196.   MChSprite1.SprColliding:=False;
  197.   MChSprite2.SprColliding:=False;
  198.   MChSprite5.SprColliding:=False;
  199.   MChSprite6.SprColliding:=False;
  200.   MChSprite6.SprHide;
  201.   MChSprite5.SprHideAfter:=True;
  202.   MChSprite2.SprShowAt(Point(Form1.MChSpriteBgr1.ClientWidth  div 2,
  203.                              Form1.MChSpriteBgr1.ClientHeight div 2));
  204.   MChSprite3.SprCruise(-1);
  205.   MChSprite4.SprCruise(-1);
  206.   end;
  207.  
  208. end.
  209.